package com.xu.book.service.impl;

import com.xu.book.bean.Book;
import com.xu.book.bean.BorrowCard;
import com.xu.book.bean.BorrowRecoder;
import com.xu.book.dao.IBorrowRecoderDao;
import com.xu.book.dao.impl.BorrowRecoderDaoimpl;
import com.xu.book.service.IBookService;
import com.xu.book.service.IBorrowCardService;
import com.xu.book.service.IBorrowRecoderService;
import com.xu.sys.bean.SysUser;
import com.xu.sys.utils.PageUtils;

import java.util.List;

public class BorrowRecoderServiceimpl implements IBorrowRecoderService {
    private IBorrowRecoderDao dao = new BorrowRecoderDaoimpl();
    private IBookService bookService = new BookServiceimpl();
    @Override
    public void listPage(PageUtils pageUtils, SysUser user) {
        List<BorrowRecoder> list = dao.listPage(pageUtils,user);
        //根据bookid查询对应的图片img
        for (BorrowRecoder borrowRecoder : list){
            if (borrowRecoder.getBookid() !=null){
                Book book = bookService.findById(borrowRecoder.getBookid());
                borrowRecoder.setImg(book.getImg());

            }
        }
        int count = dao.count(pageUtils,user);
        pageUtils.setList(list);
        pageUtils.setTotalCount(count);
    }

    @Override
    public int count(PageUtils pageUtils, SysUser user) {
        return dao.count(pageUtils,user);
    }

    @Override
    public List<BorrowRecoder> list() {
        return dao.list();
    }

    @Override
    public int save(BorrowRecoder entity) {
        return dao.save(entity);
    }

    @Override
    public BorrowRecoder findById(int id) {
        return dao.findById(id);
    }

    @Override
    public int updateById(BorrowRecoder entity) {
        return dao.updateById(entity);
    }


    @Override
    public int deleteById(int id) {
        return dao.deleteById(id);
    }
}
